package com.xizi.lotterySystem.dao.mapper;

import com.xizi.lotterySystem.dao.dataobject.ActivityPrizeDO;
import com.xizi.lotterySystem.service.enumerate.ActivityPrizeStatusEnum;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityPrizeMapper {
    @Insert("<script>" +
            " insert into activity_prize" +
            " (activity_id,prize_id,prize_amount,status,prize_tiers)" +
            " values" +
            " <foreach collection='items' item='item' index='index' separator=','> "+
            " (#{item.activityId},#{item.prizeId},#{item.prizeAmount},#{item.status},#{item.prizeTiers})"+
            " </foreach>"+
            " </script>")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    int batchInsert(@Param("items") List<ActivityPrizeDO> activityPrizeDOList);

    @Select("<script>"
            + " SELECT id"
            + " FROM prize"
            + " where"
            + "  id IN"
            + "   <foreach collection='ids' item='id' open='(' separator=',' close=')'>"
            + "     #{id}"
            + "   </foreach>"
            + "</script>")
    List<Long> selectPrizeIds(@Param("ids") List<Long> prizeIds);

    @Select("select * from activity_prize where activity_id = #{activityId}")
    List<ActivityPrizeDO> selectByActivityId(Long activityId);

    @Select("select * from activity_prize where activity_id = #{activityId} and prize_id = #{prizeId}")
    ActivityPrizeDO selectByAPID(Long activityId, Long prizeId);

    @Update("update activity_prize set status = #{status} where activity_id = #{activityId} and prize_id = #{prizeId}")
    int updateStatusById(@Param("activityId") Long activityId,
                         @Param("prizeId") Long activityPrizeId,
                         @Param("status") ActivityPrizeStatusEnum targetActivityPrizeStatus);

}
